import { FairyEditor, FairyGUI, System, UnityEngine } from "csharp";

/**
 * 加载工具
 * @author clong 2020.11.27
 */
export default class LoadUtils {

    /**
     * 加载文本
     * @param url 
     * @param handler 
     */
    public static loadText(url: string, handler: Laya.Handler): void {

        if( !System.IO.File.Exists(url) ){
            handler && handler.runWith( null );
            return;
        }
        let txt = System.IO.File.ReadAllText(url);
        if (handler) {
            handler.runWith(txt);
        }
    }

    /**
     * 加载图片
     * @param url 
     * @param handler 
     */
    public static loadImage(url: string, handler: Laya.Handler): void {

        let img = FairyEditor.VImage.New( url );
        if( img && handler ){
            // console.log("------->loadImage url: " + url );
            let texture:FairyGUI.NTexture = new FairyGUI.NTexture( img.ToTexture(true,true)  );
            handler.runWith( texture );
        }
    }
}